package com.lianniu.web.baseService.user.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.lianniu.web.base.BaseResult;
import com.lianniu.web.baseService.user.model.SuggestionVo;
import com.lianniu.web.baseService.user.service.ISuggestionService;
import com.lianniu.web.constants.ErrorCode;
import com.lianniu.web.util.StringUtil;


@Controller
@RequestMapping("/rest/suggest")
public class SuggestRestController {
	
private final static Logger logger = Logger.getLogger(SuggestRestController.class);
	@Autowired
	private ISuggestionService suggestService;
	@RequestMapping (value = {"/suggestAdd"}, method = RequestMethod.POST)
	
	public @ResponseBody BaseResult suggestAdd(HttpServletRequest request,SuggestionVo suggestVo){
	      logger.info("SuggestRestController suggestAdd begin.");      
	      logger.info("SuggestRestController suggestAdd:"+ JSON.toJSONString(suggestVo));
	      
	      String sort = request.getParameter("sort");
	      if(sort.equals("1")){
	    	  suggestVo.setSort(1);//买家问题反馈
	      }else if(sort.equals("2")){
	    	  suggestVo.setSort(2);//提交新品要求
	      }else if(sort.equals("3")){//卖家问题反馈
	    	  suggestVo.setSort(3);
	      }
	      
	      suggestVo.setDelFlag("1");
	      try {
	          logger.info("suggestAdd begin.");
	          if (StringUtil.isEmpty(suggestVo.getQuestion())) {
	              return BaseResult.fail(ErrorCode.ParaCheckErrorRetCode,
	                              ErrorCode.ParaCheckErrorRetInfo);
	          }
	        BaseResult baseResult = suggestService.addSuggest(suggestVo);
	        
	        logger.info("suggestAdd baseResult:" + JSON.toJSONString(baseResult));
	        logger.info("suggestAdd end.");
	        return baseResult;

	    } catch (Exception e) {
	      logger.error("suggestAdd error:"+e.getMessage());
	      logger.info("SuggestRestController suggestAdd end.");
	      return BaseResult.exception(e.getMessage());
	    }
	  }

}
